                            <? $frmtime = time(); ?>
                            <div class="main">
                                <h3 class="title"><?=$clabel?> &raquo; <?=$mlabel?></h3>
                                <div class="formdiv">
                                    <form method="POST" id="frmAddStudent">
                                        <table>
                                            <? if( isset($errors) ) {
                                               foreach($errors as $error) {
                                               ?>
                                            <tr>
                                                <td class="errormsg" colspan="3">
                                                    <?=$error?>    
                                                </td>
                                            </tr>   
                                               <? 
                                               } 
                                            }  ?>
                                            <? if( isset($successes) ) {
                                               foreach($successes as $success) {
                                               ?>
                                            <tr>
                                                <td class="successmsg" colspan="3">
                                                    <?=$success?>    
                                                </td>
                                            </tr>   
                                               <? 
                                               } 
                                            }  ?>
                                            <tr>
                                                <td><label for="student_name">Name*</label></td>
                                                <td>
                                                    <input type="text" class="text required" maxlength="100" minlength="3"  name="student_name" value="<?=$postdata['student_name']?>" />
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_class">Class*</label></td>
                                                <td>
                                                    <select class="text required" name="student_class">
                                                        <option value="">-- Select --</option>
                                                        <?
                                                            if(isset($classlist) && is_array($classlist) && count($classlist) > 0) {
                            	                               foreach( $classlist as $classitem ) {
                            	                                   $sel = '';
                            	                                   if(isset($postdata["student_class"]) && $classitem["class_id"]==$postdata["student_class"]) { $sel = "selected"; }
                                                        ?>
                                                                <option divisions='<?=json_encode($classitem["divisions"])?>' value="<?=$classitem["class_id"]?>" <?=$sel?>><?=$classitem["class_label"]?></option>
                                                        <?
                            	                           }
                                                        }
                                                        ?>
                                                    </select>
                                                    <script language="javascript" type="text/javascript">
                                                        $(document).ready( function() {                                                            
                                                            var _division_sel = $("#frmAddStudent select[name='student_division']");
                                                            var _class_sel = $("#frmAddStudent select[name='student_class']");
                                                            _class_sel.change( function() {
                                                                $_str_options = $("#frmAddStudent select[name='student_class'] option:selected").attr("divisions");
                                                                //console.log($_str_options);
                                                                $(_division_sel).empty();
                                                                $(_division_sel).append( new Option("-- Select --",""));                                                                
                                                                $_div_options = $.parseJSON($_str_options);
                                                                if ($_div_options != null && $_div_options.length > 0) {
                                                                    //console.log($_div_options.length);                                                                    
                                                                    $.each($_div_options, function(index, item){
                                                                        $(_division_sel).append( new Option(item.division_label,item.division_id));
                                                                    });                  
                                                                }
                                                            });
                                                        });
                                                    </script>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_division">Division</label></td>
                                                <td>
                                                    <select class="text" name="student_division">
                                                        <option value="">-- Select --</option>
                                                        <?
                                                            if(isset($divisionlist) && is_array($divisionlist) && count($divisionlist) > 0) {
                            	                               foreach( $divisionlist as $divisionitem ) {
                            	                                   $sel = '';
                            	                                   if(isset($postdata["student_division"]) && $divisionitem["division_id"]==$postdata["student_division"]) { $sel = "selected"; }
                                                        ?>
                                                                <option value="<?=$divisionitem["division_id"]?>" <?=$sel?>><?=$divisionitem["division_label"]?></option>
                                                        <?
                            	                           }
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label>Gender*</label></td>
                                                <td>
                                                    <input value="m" <? if($postdata["student_gender"] && $postdata["student_gender"] == 'm' ) echo "checked=\"checked\""; ?> class="required" type="radio" id="radGM" name="student_gender"/><label for="radGM">Male</label>
                                                    <input value="f" <? if($postdata["student_gender"] && $postdata["student_gender"] == 'f' ) echo "checked=\"checked\""; ?> type="radio" id="radGF" name="student_gender"/><label for="radGF">Female</label>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_dob">Date Of Birth*</label></td>
                                                <td>
                                                    <input type="text" readonly="true" class="stext required {validate:{date:true}}" id="student_dob" name="student_dob" value="<?=$postdata['student_dob']?>" />
                                                    <label>YYYY-MM-DD</label>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_nationality">Nationality*</label></td>
                                                <td>
                                                    <select class="text required" name="student_nationality">
                                                        <option value="">-- Select --</option>
                                                        <?
                                                            if(isset($countrylist) && is_array($countrylist) && count($countrylist) > 0) {
                            	                               foreach( $countrylist as $country ) {
                            	                                   $sel = '';
                            	                                   if(isset($postdata["student_nationality"]) && $country["id"]==$postdata["student_nationality"]) { $sel = "selected"; }
                                                        ?>
                                                                <option value="<?=$country["id"]?>" <?=$sel?>><?=$country["name"]?></option>
                                                        <?
                            	                           }
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                                <td></td>
                                            </tr>                                            
                                            <tr>
                                                <td><label for="student_rp_no">RP No.*</label></td>
                                                <td>
                                                    <input type="text" class="text required" name="student_rp_no" value="<?=$postdata['student_rp_no']?>" />
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_rp_expiry">RP Expiry</label></td>
                                                <td>
                                                    <input type="text" readonly="true" class="stext {validate:{date:true}}" id="student_rp_expiry" name="student_rp_expiry" value="<?=$postdata['student_rp_expiry']?>" />
                                                    <label>YYYY-MM-DD</label>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_father_name">Father&#39;s Name*</label></td>
                                                <td>
                                                    <input type="text" class="text required" name="student_father_name" value="<?=$postdata['student_father_name']?>" />
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_father_rp_no">Father&#39;s RP No.*</label></td>
                                                <td>
                                                    <input type="text" class="text required" name="student_father_rp_no" value="<?=$postdata['student_father_rp_no']?>" />
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_mother_name">Mother&#39;s Name*</label></td>
                                                <td>
                                                    <input type="text" class="text required" name="student_mother_name" value="<?=$postdata['student_mother_name']?>" />
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_res_area">Area*</label></td>
                                                <td>
                                                    <select class="text required" name="student_res_area" id="student_res_area<?=$frmtime?>">
                                                        <option value="">-- Select --</option>
                                                        <?
                                                            if(isset($arealist) && is_array($arealist) && count($arealist) > 0) {
                            	                               foreach( $arealist as $areaitem ) {
                            	                                   $sel = '';
                            	                                   if(isset($postdata["student_res_area"]) && $areaitem["area_id"]==$postdata["student_res_area"]) { $sel = "selected"; }
                                                        ?>
                                                                <option value="<?=$areaitem["area_id"]?>" <?=$sel?>><?=$areaitem["area_name"]?></option>
                                                        <?
                            	                           }
                                                        }
                                                        ?>
                                                    </select>
                                                    <a id="linkNewArea<?=$frmtime?>" href="javascript:void(0);" class="add">
                                                        <img src="/css/images/add.png"/>
                                                    </a>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label>Transport Required*</label></td>
                                                <td>
                                                    <input value="0" <? if($postdata["student_transport_required"] && $postdata["student_transport_required"] == '0' ) echo "checked=\"checked\""; ?> class="required" type="radio" id="radTN" name="student_transport_required"/><label for="radTN">No</label>
                                                    <input value="1" <? if($postdata["student_transport_required"] && $postdata["student_transport_required"] == '1' ) echo "checked=\"checked\""; ?> type="radio" id="radTY<?=$frmtime?>" name="student_transport_required"/><label for="radTY<?=$frmtime?>">Yes</label>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_bus_no<?=$frmtime?>">Bus No.</label></td>
                                                <td>
                                                    <select id="student_bus_no<?=$frmtime?>" class="text" name="student_bus_no">
                                                        <option value="">-- Select --</option>
                                                        <?
                                                            if(isset($buslist) && is_array($buslist) && count($buslist) > 0) {
                            	                               foreach( $buslist as $bus ) {
                            	                                   $sel = '';
                            	                                   if(isset($postdata["student_bus_no"]) && $bus["value"]==$postdata["student_bus_no"]) { $sel = "selected"; }
                                                        ?>
                                                                <option value="<?=$bus["value"]?>" <?=$sel?>><?=$bus["label"]?></option>
                                                        <?
                            	                           }
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_address">Address*</label></td>
                                                <td>
                                                    <textarea rows="3" cols="20" class="text required" maxlength="200" minlength="10" name="student_address"><?=$postdata['student_address']?></textarea>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_phone_mob">Mobile*</label></td>
                                                <td>
                                                    <input type="text" class="text required digits" name="student_phone_mob" value="<?=$postdata['student_phone_mob']?>" />
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_phone_office">Telephone (Office)</label></td>
                                                <td>
                                                    <input type="text" class="text digits" name="student_phone_office" value="<?=$postdata['student_phone_office']?>" />
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_phone_res">Telephone (Residence)</label></td>
                                                <td>
                                                    <input type="text" class="text digits" name="student_phone_res" value="<?=$postdata['student_phone_res']?>" />
                                                </td>
                                                <td></td>
                                            </tr>                                            
                                            <tr>
                                                <td><label for="student_email">Email*</label></td>
                                                <td>
                                                    <input type="text" class="text required email" name="student_email" value="<?=$postdata['student_email']?>" />
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_father_workplace">Father&#39;s Work Place</label></td>
                                                <td>
                                                    <textarea rows="3" cols="20" class="text" maxlength="200" minlength="10" name="student_father_workplace"><?=$postdata['student_father_workplace']?></textarea>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label>Left Handed*</label></td>
                                                <td>
                                                    <input value="1" <? if(isset($postdata["student_left_handed"]) && $postdata["student_left_handed"] == '1' ) echo "checked=\"checked\""; ?> class="required" type="radio" id="radSSA" name="student_left_handed"/><label for="radSSA">Yes</label>
                                                    <input value="0" <? if(isset($postdata["student_left_handed"]) && $postdata["student_left_handed"] == '0' ) echo "checked=\"checked\""; ?> type="radio" id="radSSR" name="student_left_handed"/><label for="radSSR">No</label>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_allergy">Allergies if any</label></td>
                                                <td>
                                                    <textarea rows="2" cols="20" class="text" maxlength="200" name="student_allergy"><?=$postdata['student_allergy']?></textarea>
                                                </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td><label for="student_comment">Comments</label></td>
                                                <td>
                                                    <textarea rows="3" cols="20" class="text" maxlength="1000" name="student_comment"><?=$postdata['student_comment']?></textarea>
                                                </td>
                                                <td></td>
                                            </tr>
                                        	<tr>
                                        		<td></td>
                                        		<td colspan="2">
                                                    <input class="button" type="submit" name="btnAddStudent" value="Save" id="btnAddStudent" />
                                                    <input class="button" type="reset" value="Cancel" id="btnreset" />
                                                </td>
                                        	</tr>
                                        </table>
                                	</form>
                                    <script language="javascript" type="text/javascript">
                                        if(typeof jQuery == 'undefined') {
                                            alert('Invalid Request');
                                            window.location = "/";
                                        }
                                        $(document).ready( function() {
                                            $("#frmAddStudent").validate({
                                                rules: {
                                                    student_bus_no: {
                                                        required: "#radTY<?=$frmtime?>:checked"
                                                    }
                                                },
                                                errorPlacement: function(error, element) {
                                                    placeError(error, element);
                                                },
                                                submitHandler: function(form) {
                                                    var cui = $('#contenttabs .ui-tabs-panel:visible');                                                                                                        
                                               	    var jqxhr = $.post(
                                                        "/student/addstudent", 
                                                        $("#frmAddStudent").serialize(), 
                                                        function (data) {
                                                            $(cui).html(data);
                                                        }
                                                    );
                                                    $(cui).html('<div id="loadingdiv"><div class="centerdiv"><strong>Processing</strong><br/><img src="/images/ajaxloader.gif" /></div></div>');
                                                }
                                            });
                                            $("#frmAddStudent input[name='student_dob']").datepicker({ 
                                                yearRange: '-6:-2',
                                                dateFormat: 'yy-mm-dd',
                                                changeMonth: true,
                                                changeYear: true,
                                                maxDate: '+16y' 
                                            });
                                            $("#frmAddStudent input[name='student_rp_expiry']").datepicker({ 
                                                dateFormat: 'yy-mm-dd',
                                                changeMonth: true,
                                                changeYear: true
                                            });
                                            $("#frmAddStudent input[type='reset']").click( function() {
                                                $('#frmAddStudent label.error').remove();
                                            });
                                            
                                            var $rcdialog = $("#divaddarea<?=$frmtime?>").dialog({ 
                                                autoOpen: false, 
                                                title: 'Add New Area',
                                                resizable: false,
                                                width: 500,
                                                modal: true,
                                                buttons : {
                                                    "Create": function() {
                                                        var area_name = $("#area_name<?=$frmtime?>").val();
                                                        var area_code = $("#area_code<?=$frmtime?>").val();
                                                        if(area_name!="") {
                                                       	    var jqxhr = $.post(
                                                                "/transport/addarea", 
                                                                { 
                                                                    'btnAddArea': true,
                                                                    'area_name': area_name,
                                                                    'area_code':area_code,
                                                                    'req_type':'json' 
                                                                }, 
                                                                function (data) {
                                                                    //console.log(data);
                                                                    var objResult = $.parseJSON(data);
                                                                    if(objResult.status == "S") {
                                                                        $("#student_res_area<?=$frmtime?>").append('<option value="'+objResult.id+'" selected="selected">'+objResult.label+'</option>');
                                                                        $("#add_area_msg<?=$frmtime?>").html("");
                                                                        $("#area_name<?=$frmtime?>").val("");
                                                                        $("#area_code<?=$frmtime?>").val("");
                                                                        $rcdialog.dialog('close');
                                                                    } else {
                                                                        var error_msg = "";
                                                                        var error_arr = objResult.errors;
                                                                        for(var i=0; i<error_arr.length; i++) {
                                                                            if(error_msg != "") {
                                                                                error_msg += "\n";
                                                                            }
                                                                            error_msg += error_arr[i];
                                                                        }
                                                                        $("#add_area_msg<?=$frmtime?>").html(error_msg);
                                                                    }
                                                                }
                                                            );
                                                            $("#add_area_msg<?=$frmtime?>").html("In progress.");
                                                        } else {
                                                            $("#add_area_msg<?=$frmtime?>").html("Area name cannot be empty.");
                                                        }
                                                    },
                                                    "Cancel": function() {
                                                        $( this ).dialog( "close" );
                                                    }
                                                } 
                                            });
                                            
                                            $("#linkNewArea<?=$frmtime?>").click(function() {
                                                $rcdialog.dialog('open');
                                            });
                                        });
                                    </script>
                                 </div>
                            </div>
                            <div id="divaddarea<?=$frmtime?>" style="display: none;">
                                <table width="100%" cellpadding="3">
                                    <tr>
                                        <td width="100"><label>Area Name*:</label></td>
                                        <td><input type="text" name="area_name" id="area_name<?=$frmtime?>" style="width: 250px;" /></td>
                                    </tr>
                                    <tr>
                                        <td width="100"><label>Area Code:</label></td>
                                        <td><input type="text" name="area_code" id="area_code<?=$frmtime?>" style="width: 250px;" /></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <div style="color: red; text-align: center;"><label id="add_area_msg<?=$frmtime?>"></label></div>
                                        </td>
                                    </tr>
                                </table>
                             </div>